fix(browser): ignore channel events in a tester opened as a top-level window (fix #9379)#9381
Open
simshanith wants to merge 2 commits into
Open
fix(browser): ignore channel events in a tester opened as a top-level window (fix #9379)#9381simshanith wants to merge 2 commits into
simshanith wants to merge 2 commits into
Conversation
sheremet-va
requested changes
Jan 4, 2026
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
… window (fix vitest-dev#9379) A test can open the tester page as a top-level window, e.g. by clicking an anchor with target="_blank" whose href resolves to the tester URL (href="" resolves to the current page, ?sessionId=...&iframeId=... included). The duplicate tester joins the BroadcastChannel with the same iframeId and echoes ack:/response: events back to the real tester, each received message spawning an ack and a response in the twin, generating events recursively until the run fails with hundreds of thousands of "Unknown event" errors and the orchestrator times out waiting for the real tester's acknowledgements. The tester now only participates in the iframe channel when it is actually embedded in the orchestrator.
simshanith
force-pushed
the
simshanith/response-event-loop-guard
branch
from
July 7, 2026 03:33
da0e8c0 to
361c463
Compare
simshanith
added a commit
to simshanith/lit-ui-router
that referenced
this pull request
Jul 7, 2026
…wser patch (#186) Replaces the symptom filter (dropping ready/response:* events by name) with the root-cause guard from vitest-dev/vitest#9381: a tester opened as a top-level window (e.g. a test clicking <a target="_blank"> at the tester URL) joins the BroadcastChannel with the same iframeId and echoes response: events back recursively. The tester now only participates in the iframe channel when actually embedded in the orchestrator. Refs #69
Author
|
@sheremet-va this is ready for another look — rewrote it from scratch, and your review was right on both counts:
New regression test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #9379 — the recursive
Unknown event: response:response:...:execute/cleanupstorm in browser mode.Root cause (traced)
My earlier explanation (BroadcastChannel echoing to the sender) was wrong, as pointed out in review — thanks. The actual mechanism:
src = "/?sessionId=<id>&iframeId=<id>"(createTestIframe,packages/browser/src/client/orchestrator.ts)./with a livesessionId(packages/browser/src/node/serverTester.ts).href=""resolves to the current URL including the query string. So a test that clicks<a href="" target="_blank">— or ctrl/meta-clicks a relative link, which routers deliberately don'tpreventDefault()— opens a popup at the tester URL. The popup boots a second, top-level tester with the samesessionIdand the sameiframeId, joining the sameBroadcastChannel.From then on the two same-
iframeIdtesters ping-pong:ready. The real tester receives it (theiframeIdcheck passes — it's its own id), postsack:ready, falls into thedefault:case (Unknown event: ready), and thefinallyblock postsresponse:ready.ack:readyandresponse:readyand does the same. Every received message spawns anack:and aresponse:in the twin, so growth is exponential:ack:response:response:ack:...:ready.The iframe ... did not acknowledge the "cleanup" message within 60000ms.The orchestrator already ignores
response:/ack:events in itsdefault:case ("ignore acknowledgements and responses to events we sent", added in #10656); the tester side had no equivalent protection against a duplicate participant.This also explains the coverage report in #9379 (grant-progress): anything that opens the tester URL in a second browsing context triggers the same loop.
Fix
The tester only participates in the iframe channel when it is actually embedded in the orchestrator (
window.self !== window.top): a top-level copy of the page neither handles channel messages nor announcesready. This removes the duplicate participant instead of filtering event names, addressing the review feedback that the previousstartsWith('response:')guard only hid the symptom.Numbers (fixture: one test clicking
<a href="" target="_blank">+ one trivial follow-up file, chromium)Unknown event: ...Regression test
test/browser/specs/duplicate-tester.test.ts(same style asspecs/readiness.test.ts): runs the popup-click scenario inline and asserts noUnknown eventin stderr, exit code 0, and both tests passing.Verified failing without the fix and passing with it on chromium, firefox and webkit:
Unknown eventerrors in ~42s), webkit exit 1 (446k errors), firefox exit 1 (inner run flooded until the spec's 60s timeout)specs/readiness.test.ts(3 tests over the same handshake machinery) still passes on all threeAI disclosure
Root-cause tracing, the fix, and the regression test were developed with assistance from Claude Code; I reviewed all changes and the verification runs above were executed locally.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci. (duplicate-tester+readinessspecs verified on chromium/firefox/webkit; a full localtest/browserrun hits pre-existing failures that reproduce identically on unmodified main in my environment, so relying on CI for the full matrix)Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.